/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package com.mycompany.ndbnbndb;

import javax.swing.JOptionPane;

/**
 *
 * @author Administrator
 */
public class NewJFrame extends javax.swing.JFrame {

    /**
     * Creates new form NewJFrame
     */
    public NewJFrame() {
        initComponents();
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel2 = new javax.swing.JPanel();
        AC = new javax.swing.JButton();
        add = new javax.swing.JButton();
        substract = new javax.swing.JButton();
        multiply = new javax.swing.JButton();
        number1 = new javax.swing.JButton();
        number2 = new javax.swing.JButton();
        number3 = new javax.swing.JButton();
        divide = new javax.swing.JButton();
        number4 = new javax.swing.JButton();
        number5 = new javax.swing.JButton();
        number6 = new javax.swing.JButton();
        point = new javax.swing.JButton();
        number7 = new javax.swing.JButton();
        number8 = new javax.swing.JButton();
        number9 = new javax.swing.JButton();
        number0 = new javax.swing.JButton();
        jPanel3 = new javax.swing.JPanel();
        screen = new javax.swing.JTextField();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        jPanel2.setLayout(new java.awt.GridLayout(4, 4));

        AC.setText("AC");
        AC.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                ACActionPerformed(evt);
            }
        });
        jPanel2.add(AC);

        add.setText("+");
        add.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                addActionPerformed(evt);
            }
        });
        jPanel2.add(add);

        substract.setText("-");
        substract.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                substractActionPerformed(evt);
            }
        });
        jPanel2.add(substract);

        multiply.setText("*");
        multiply.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                multiplyActionPerformed(evt);
            }
        });
        jPanel2.add(multiply);

        number1.setText("1");
        number1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                number1ActionPerformed(evt);
            }
        });
        jPanel2.add(number1);

        number2.setText("2");
        number2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                number2ActionPerformed(evt);
            }
        });
        jPanel2.add(number2);

        number3.setText("3");
        number3.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                number3ActionPerformed(evt);
            }
        });
        jPanel2.add(number3);

        divide.setText("/");
        divide.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                divideActionPerformed(evt);
            }
        });
        jPanel2.add(divide);

        number4.setText("4");
        number4.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                number4ActionPerformed(evt);
            }
        });
        jPanel2.add(number4);

        number5.setText("5");
        number5.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                number5ActionPerformed(evt);
            }
        });
        jPanel2.add(number5);

        number6.setText("6");
        number6.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                number6ActionPerformed(evt);
            }
        });
        jPanel2.add(number6);

        point.setText(".");
        point.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                pointActionPerformed(evt);
            }
        });
        jPanel2.add(point);

        number7.setText("7");
        number7.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                number7ActionPerformed(evt);
            }
        });
        jPanel2.add(number7);

        number8.setText("8");
        number8.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                number8ActionPerformed(evt);
            }
        });
        jPanel2.add(number8);

        number9.setText("9");
        number9.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                number9ActionPerformed(evt);
            }
        });
        jPanel2.add(number9);

        number0.setText("0");
        number0.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                number0ActionPerformed(evt);
            }
        });
        jPanel2.add(number0);

        jPanel3.setBorder(javax.swing.BorderFactory.createTitledBorder("计算机"));

        screen.setHorizontalAlignment(javax.swing.JTextField.RIGHT);
        screen.setText("0");

        javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
        jPanel3.setLayout(jPanel3Layout);
        jPanel3Layout.setHorizontalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addComponent(screen)
                .addContainerGap())
        );
        jPanel3Layout.setVerticalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(screen, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, 400, Short.MAX_VALUE)
            .addGroup(layout.createSequentialGroup()
                .addComponent(jPanel3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(jPanel3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, 327, Short.MAX_VALUE)
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    ndb ndb = new ndb();
     private boolean newInput = true;
     String text = "";
    private void ACActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_ACActionPerformed

this.screen.setText("0");

      
ndb.ac();
        
    //    JOptionPane.showMessageDialog(this, "222222222222222");

    }//GEN-LAST:event_ACActionPerformed


    private void number1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_number1ActionPerformed
        // TODO add your handling code here:
          if(newInput){
            screen.setText(0+"");
        }
        
        if(screen.getText().trim().equals("0")){
            screen.setText("1");
        }else{
            screen.setText(screen.getText()+"1");
        }
        newInput = false;

    }//GEN-LAST:event_number1ActionPerformed

    private void number2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_number2ActionPerformed
     // TODO add your handling code here:
       if(newInput){
            screen.setText(0+"");
        }
        
        if(screen.getText().trim().equals("0")){
            screen.setText("2");
        }else{
            screen.setText(screen.getText()+"2");
        }
        newInput = false;
    }//GEN-LAST:event_number2ActionPerformed

    private void addActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_addActionPerformed
        // TODO add your handling code here:
       String screenThing =  screen.getText();
         try{
            double screenNumber = Double.parseDouble(screenThing);
            ndb.add(screenNumber);
            screen.setText(ndb.getValue()+"");
            newInput = true;
        }catch(Exception e){
            e.printStackTrace();
            //TODO: screenThing represent wrong real number.
        }


    }//GEN-LAST:event_addActionPerformed

    private void number3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_number3ActionPerformed
        // TODO add your handling code here:
          if(newInput){
            screen.setText(0+"");
        }
        
        if(screen.getText().trim().equals("0")){
            screen.setText("3");
        }else{
            screen.setText(screen.getText()+"3");
        }
        newInput = false;
    }//GEN-LAST:event_number3ActionPerformed

    private void number9ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_number9ActionPerformed
         // TODO add your handling code here:
           if(newInput){
            screen.setText(0+"");
        }
        
        if(screen.getText().trim().equals("0")){
            screen.setText("9");
        }else{
            screen.setText(screen.getText()+"9");
        }
        newInput = false;
    }//GEN-LAST:event_number9ActionPerformed

    private void number4ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_number4ActionPerformed
        // TODO add your handling code here:
          if(newInput){
            screen.setText(0+"");
        }
        
        if(screen.getText().trim().equals("0")){
            screen.setText("4");
        }else{
            screen.setText(screen.getText()+"4");
        }
        newInput = false;
    }//GEN-LAST:event_number4ActionPerformed

    private void number5ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_number5ActionPerformed
        // TODO add your handling code here:
          if(newInput){
            screen.setText(0+"");
        }
        
        if(screen.getText().trim().equals("0")){
            screen.setText("5");
        }else{
            screen.setText(screen.getText()+"5");
        }
        newInput = false;
    }//GEN-LAST:event_number5ActionPerformed

    private void number6ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_number6ActionPerformed
        // TODO add your handling code here:
          if(newInput){
            screen.setText(0+"");
        }
        
        if(screen.getText().trim().equals("0")){
            screen.setText("6");
        }else{
            screen.setText(screen.getText()+"6");
        }
        newInput = false;
    }//GEN-LAST:event_number6ActionPerformed

    private void number7ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_number7ActionPerformed
        // TODO add your handling code here:
          if(newInput){
            screen.setText(0+"");
        }
        
        if(screen.getText().trim().equals("0")){
            screen.setText("7");
        }else{
            screen.setText(screen.getText()+"7");
        }
        newInput = false;
    }//GEN-LAST:event_number7ActionPerformed

    private void number8ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_number8ActionPerformed
        // TODO add your handling code here:
          if(newInput){
            screen.setText(0+"");
        }
        
        if(screen.getText().trim().equals("0")){
            screen.setText("8");
        }else{
            screen.setText(screen.getText()+"8");
        }
        newInput = false;
    }//GEN-LAST:event_number8ActionPerformed

    private void number0ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_number0ActionPerformed
        // TODO add your handling code here:
          if(newInput){
            screen.setText(0+"");
        }
        
        if(screen.getText().trim().equals("0")){
            screen.setText("0");
        }else{
            screen.setText(screen.getText()+"0");
        }
        newInput = false;
    }//GEN-LAST:event_number0ActionPerformed

    private void substractActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_substractActionPerformed
        // TODO add your handling code here:
          String screenThing =  screen.getText();
         try{
            double screenNumber = Double.parseDouble(screenThing);
            ndb.substract(screenNumber);
            screen.setText(ndb.getValue()+"");
            newInput = true;
        }catch(Exception e){
            e.printStackTrace();
            //TODO: screenThing represent wrong real number.
    }//GEN-LAST:event_substractActionPerformed
    }
    private void multiplyActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_multiplyActionPerformed
        // TODO add your handling code here:
        String screenThing =  screen.getText();
         try{
            double screenNumber = Double.parseDouble(screenThing);
            ndb.multiply(screenNumber);
            screen.setText(ndb.getValue()+"");
            newInput = true;
        }catch(Exception e){
            e.printStackTrace();
            //TODO: screenThing represent wrong real number.
    }//GEN-LAST:event_multiplyActionPerformed
    }
    private void divideActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_divideActionPerformed
        // TODO add your handling code here:
        String screenThing =  screen.getText();
         try{
            double screenNumber = Double.parseDouble(screenThing);
            ndb.divide(screenNumber);
            screen.setText(ndb.getValue()+"");
            newInput = true;
        }catch(Exception e){
            e.printStackTrace();
            //TODO: screenThing represent wrong real number.
    }//GEN-LAST:event_divideActionPerformed
    }
    private void pointActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_pointActionPerformed
        // TODO add your handling code here: 
        if(newInput){
            screen.setText(0+"");
        }
        
        if(screen.getText().trim().equals("0")){
            screen.setText(".");
        }else{
            screen.setText(screen.getText()+".");
        }
        newInput = false;
        
    }//GEN-LAST:event_pointActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(NewJFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(NewJFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(NewJFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(NewJFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new NewJFrame().setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton AC;
    private javax.swing.JButton add;
    private javax.swing.JButton divide;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JButton multiply;
    private javax.swing.JButton number0;
    private javax.swing.JButton number1;
    private javax.swing.JButton number2;
    private javax.swing.JButton number3;
    private javax.swing.JButton number4;
    private javax.swing.JButton number5;
    private javax.swing.JButton number6;
    private javax.swing.JButton number7;
    private javax.swing.JButton number8;
    private javax.swing.JButton number9;
    private javax.swing.JButton point;
    private javax.swing.JTextField screen;
    private javax.swing.JButton substract;
    // End of variables declaration//GEN-END:variables
}
